/*
 * portfolio.cpp
 *
 *  Created on: 11/giu/2014
 *      Author: ammin
 */

#include "portfolio.h"


Portfolio::Portfolio(CASH initialCashAmount) : m_money(initialCashAmount){

}

bool Portfolio::Withdraw(CASH amount){
	bool success = false;

	if(amount <= m_money){
		m_money -= amount;
		success = true;
	}

	return success;
}

void Portfolio::Deposit(CASH amount){
	m_money += amount;
}

CASH Portfolio::GetAmount() const{
	return m_money;
}

void Portfolio::Add(Position *pos){
	m_vPositions.push_back(pos);

	m_iCurrentPosition = m_vPositions.begin();
}

void Portfolio::Remove(Position *pos){
	for(unsigned int i = 0; i < m_vPositions.size(); i++){
		if (m_vPositions[i]== pos){
			m_vPositions.erase(m_vPositions.begin()+i);
			break;
		}
	}

	if(m_vPositions.size()){
		m_iCurrentPosition = m_vPositions.begin();
	}
}

bool Portfolio::GetPosition(Position *nextPos){
	bool hasPositions = false;

	if(m_vPositions.size()){
		hasPositions = true;

		if(m_iCurrentPosition == m_vPositions.end())
			m_iCurrentPosition = m_vPositions.begin();
		else
			m_iCurrentPosition++;

		nextPos = *m_iCurrentPosition;
	}

	return hasPositions;
}

